package com.my;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by YJH on 2017/6/25 9:50.
 */
public class ForwardServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        super.doGet(request, response);
        System.out.println("ForwardServlet → doGet()");

        //请求转发
        //1.调用HttpServletRequest的getRequestDispatcher方法获得RequestDispatcher对象，调用getRequestDispatcher()需要传入地址
        RequestDispatcher dispatcher = request.getRequestDispatcher("/testServlet");
        //2.调用RequestDispatcher的forward(request, response);进行请求转发
        dispatcher.forward(request, response);
    }
}
